1. Field
The described embodiments relate to techniques for handling pointers in program code. More specifically, the described embodiments relate to a technique for handling pointers in program code in a system that supports multiple address spaces.
2. Related Art
Through the use of certain programming languages (e.g., OpenCL, OpenCL C++, CUDA, etc.), programmers are able to use secondary processors (e.g., graphics processing units (GPUs), additional central processing unit (CPUs), embedded processors, etc.) for performing operations that historically have been performed by a CPU alone. For example, some of these programming languages enable a GPU to be used to offload certain types of operations from a CPU, thereby freeing the CPU to perform other operations.
Some of these programming languages include support for multiple disjoint address spaces that can be used to control accesses to explicitly-managed memories in the secondary processors that are furnished with such memories. For example, the OpenCL programming language includes separate global, local, constant, and private address spaces. Although these address spaces are useful for handling memory accesses, their use introduces significant limitations to the underlying programming languages. One such limitation is that pointers within program code must be expressly directed to a particular address space. Thus, for each pointer, a programmer is required to state an address space to which the pointer is directed.
The requirement that pointers be handled in this way means that composing program code in these programming languages can be difficult. For example, if different versions of a function are to be implemented with pointers to different address spaces, multiple versions of the same function would need to be implemented. As another example, the management of implicit pointers, such as a class's this pointer (in the programming languages that support the this pointer), can be difficult when the implicit pointer can be applied to multiple address spaces.
Further complicating this problem is the fact that some of these programming languages support a “generic” address space that is used to refer generally to an underlying set of specific address spaces. In such programming languages, upon encountering a pointer to the generic address space at runtime, the system is required to dynamically determine an actual address space for the pointer before proceeding with subsequent operations.